package com.cxrj.zhsq.partyMember.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.cxrj.zhsq.partyMember.dao.PartyMemberMienMapper;
import com.cxrj.zhsq.partyMember.entity.PartyMemberMien;
import com.cxrj.zhsq.partyMember.service.PartyMemberMienService;
import com.cxrj.zhsq.utils.HtmlUtil;
import com.cxrj.zhsq.utils.IpUtil;
import com.cxrj.zhsq.utils.SqlCondition;
import com.cxrj.zhsq.utils.UploadController;

@Service
public class PartyMemberMienServiceImpl implements PartyMemberMienService {
	
	@Resource
	private PartyMemberMienMapper memberMienMapper;

	@Override
	public Map<String, Object> insertPartyMemberMien(PartyMemberMien memberMien, HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap=new HashMap<>();
		memberMien.setmTime(new Date());
		memberMien.setmState("0");
		int a=memberMienMapper.insertSelective(memberMien);
		resultMap.put("result", a);
		return resultMap;
	}

	@Override
	public Map<String, Object> selectPartyMemberMienPage(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> sqlMap = SqlCondition.getBaseCondition(request, response);
		String kod=request.getParameter("kod");
		String sqlStr = " where 1=1 ";
		if(kod != null && !kod.equals("")){
			sqlStr += " and m_title like " + '"' + '%' + kod + '%' + '"';
		}
		sqlMap.put("condition",sqlStr);
		int count = memberMienMapper.selectCount(sqlMap);
		List<Map<String, Object>> list = memberMienMapper.selectList(sqlMap);
		resultMap.put("total", count);
		resultMap.put("recordsFiltered", count);
		resultMap.put("rows", list);
		return resultMap;
	}

	@Override
	public Map<String, Object> selectPartyMemberMienById(String mId, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		PartyMemberMien memberMien = memberMienMapper.selectByPrimaryKey(mId);
		if (memberMien.getmContent() != null && !memberMien.getmContent().equals("")) {
			memberMien.setmContent(HtmlUtil.getAbsSource(memberMien.getmContent(), "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/"));
		}
		resultMap.put("result", memberMien);
		return resultMap;
	}

	@Override
	public Map<String, Object> updatePartyMemberMien(PartyMemberMien memberMien, HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap=new HashMap<>();
		int a=memberMienMapper.updateByPrimaryKeySelective(memberMien);
		resultMap.put("result", a);
		return resultMap;
	}

	@Override
	public Map<String, Object> updatePartyMemberMienState(PartyMemberMien memberMien, HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap=new HashMap<>();
		memberMien.setmReleaseTime(new Date());
		int a=memberMienMapper.updateByPrimaryKeySelective(memberMien);
		resultMap.put("result", a);
		return resultMap;
	}

	@Override
	public Map<String, Object> deletePartyMemberMien(String mId,HttpServletRequest request ,HttpServletResponse response) {
		Map<String, Object> resultMap=new HashMap<>();
		int a=0;
		if(UploadController.deleteDir(mId, request, response)) {
			a=memberMienMapper.deleteByPrimaryKey(mId);
		}
		resultMap.put("result", a);
		return resultMap;
	}

	@Override
	public Map<String, Object> selectMemberMien(String dataIndex, String pageCount) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		sqlMap.put("start", Integer.parseInt(dataIndex));
		sqlMap.put("length", Integer.parseInt(pageCount));
		resultMap.put("list", memberMienMapper.selectMemberMien(sqlMap));
		return resultMap;
	}
}
